home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / initDataServer.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.7 KB  |  131 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. proc int catchdevice(string $dev, string $server)
  18. {
  19.   return catch( `defineDataServer -d $dev -s $server` );
  20. }
  21.  
  22. proc string buildConfigClause(string $config)
  23. {
  24.     int $debug = 0;
  25.     string $func  = "buildConfigClause";
  26.  
  27.     if ($debug) trace(" // config: " + $config + "\n");
  28.  
  29.     // strip off leading white space
  30.     $config = substitute("^[     ]*", $config, "" );
  31.  
  32.     if ( "" != match("^-", $config ) ) {
  33.         if ($debug) trace("// " + $func + ": explicit config option specified\n" );
  34.         return " " + $config + " ";
  35.     }
  36.  
  37.     // Search for the config file in the follow places
  38.     // if absolute path... use it
  39.     // .
  40.     // $MAYA_USER_CONFIG/mocap
  41.     // /usr/aw/userconfig/maya/mocap
  42.     //
  43.     string $configPath[] = { ".", 
  44.                              "$MAYA_USER_CONFIG/mocap", 
  45.                              "/usr/aw/userconfig/maya/mocap" };
  46.     
  47.     string $iFoundIt = searchPathArray($config,$configPath);
  48.  
  49.     if ($debug) trace("// " + $func + ": config file :" + $iFoundIt + "\n" );
  50.  
  51.     // set the config flag and return
  52.     if ( $iFoundIt == "" )
  53.         return " ";
  54.  
  55.     return " -c " + $iFoundIt + " ";
  56. }     
  57.  
  58. global proc int initDataServer(string $dev, string $server, string $host, 
  59.                     string $config, string $options, int $napTime )
  60. {
  61.     if (!`licenseCheck -m "edit" -typ "complete"`) {
  62.         return -1;
  63.     }
  64.  
  65.     int $debug  = 0;
  66.     int $result = 0; // success
  67.  
  68.     // First check the list of extant devices
  69.     string $devList[] = `listInputDevices`;
  70.     string $aDev; 
  71.     for ( $aDev in $devList) {
  72.         if ( $aDev == $dev )
  73.             return $result;
  74.     }
  75.  
  76.     // Now try to define
  77.     if ( catchdevice($dev, $server ) ) 
  78.     {
  79.         if (`about -evalVersion`)
  80.         {
  81.             // The evaluation version of Maya cannot launch external
  82.             // programs, they will have to launch it themselves.
  83.             //
  84.             error("The dataServer is not running and Maya PLE cannot start it.\n");
  85.             return -1; // failure;
  86.         }
  87.         
  88.         // Ack, we could find it, try to launch..
  89.         if ( $debug ) trace("Server not running, attempt to launch " + $server + "\n");
  90.  
  91.         // $result = -1; // failure
  92.         if ( $host == "localhost" )
  93.         {
  94.             // Build the command string... 
  95.             $config = buildConfigClause($config);
  96.             string $cmd = $server + " -d " + $config + $options;
  97.             if (`exists Win32Init`)
  98.             {
  99.                 $cmd = "start " + $cmd;
  100.             }
  101.             else
  102.             {
  103.                 $cmd = $cmd + " &";
  104.             }
  105.             if ( $debug )
  106.                 system("echo \$PATH");  // GG: ignore, debug only
  107.             system( $cmd);  // GG: okay for NT
  108.             if ( $napTime > 0) 
  109.             {
  110.                 // This will take a brief nap, so bring up the wait cursor...
  111.                 waitCursor -st true;
  112.  
  113.                 if ( $napTime < 10 )
  114.                     $napTime = 10;
  115.                 $cmd = "sleep " + $napTime;
  116.                 system( $cmd);  // GG: need "sleep" for NT
  117.                 
  118.                 // We have awakened...
  119.                 waitCursor -st false;
  120.             }
  121.             if ( catchdevice($dev, $server ) )
  122.             {    
  123.                 $result = -1; // failure
  124.             }
  125.         }
  126.         else // we could support remote launch here...
  127.             $result = -1; // failure
  128.     }
  129.     return $result;        
  130. }
  131.